import unittest


import selenium.webdriver as webdriver
import time
from page_object_cargocn.login_page import LoginPage


class TestLogin(unittest.TestCase):

    lp = None

    @classmethod
    def setUpClass(cls):
        print("execute setUpClass")

    @classmethod
    def tearDownClass(cls):
        print("execute tearDownClass")

    def setUp(self):
        print("execute setUp")
        print('start...')
        print('打开浏览器')
        driver = webdriver.Chrome()
        print('打开登录界面')
        self.lp = LoginPage(driver)

    def tearDown(self):
        print("execute tearDown")
        self.lp.quit()

    def test_login_one(self):
        print('execute test_login_one')

        var_user = '18555059369'
        var_pwd = '238200'
        print('执行登录')
        self.lp.login(var_user, var_pwd)
        print('用户' + var_user + '登录成功！')
        print('登录前界面已截图保存！')
        self.lp.snapshot('loginsnapshot.png')
        time.sleep(1)
        self.lp.snapshot('login_success_snapshot.png')
        print('登录后界面已截图保存！')
        cur_url = self.lp.get_driver().current_url
        self.assertEqual('http://hhycs.cargocn.com/#/welcome', cur_url, 'url must equal')


if __name__ == '__main__':
    suite = unittest.TestSuite()
    # TestLogin是要测试的类名，test_login_one是要执行的测试方法
    suite.addTest(TestLogin("test_login_one"))
    runner = unittest.TextTestRunner()
    runner.run(suite)
